package main

import (
	"fmt"
	rxgo "hw06/rxgo-master"
)

func main() {
	fmt.Println("以下测试输入皆为：1，8，3，4，2，1，2，5")
	res := []int{}
	ob := rxgo.Just(1, 8, 3, 4, 2, 1, 2, 5).Map(func(x int) int {
		return x
	}).Distinct()
	ob.Subscribe(func(x int) {
		res = append(res, x)
	})
	fmt.Print("调用Distinct(): ")
	for _, val := range res {
		fmt.Print(val, "  ")
	}
	fmt.Print("\n")

	res = []int{}
	ob = rxgo.Just(1, 8, 3, 4, 2, 1, 2, 5).Map(func(x int) int {
		return x
	}).ElementAt(3)
	ob.Subscribe(func(x int) {
		res = append(res, x)
	})
	fmt.Print("调用ElementAt(3): ", res[0])
	fmt.Print("\n")

	res = []int{}
	ob = rxgo.Just(1, 8, 3, 4, 2, 1, 2, 5).Map(func(x int) int {
		return x
	}).First()
	ob.Subscribe(func(x int) {
		res = append(res, x)
	})
	fmt.Print("调用First(): ", res[0])
	fmt.Print("\n")

	res = []int{}
	ob = rxgo.Just(1, 8, 3, 4, 2, 1, 2, 5).Map(func(x int) int {
		return x
	}).Last()
	ob.Subscribe(func(x int) {
		res = append(res, x)
	})
	fmt.Print("调用Last(): ", res[0])
	fmt.Print("\n")

	res = []int{}
	ob = rxgo.Just(1, 8, 3, 4, 2, 1, 2, 5).Map(func(x int) int {
		return x
	}).Skip(3)
	ob.Subscribe(func(x int) {
		res = append(res, x)
	})
	fmt.Print("调用Skip(3): ")
	for _, val := range res {
		fmt.Print(val, "  ")
	}
	fmt.Print("\n")

	res = []int{}
	ob = rxgo.Just(1, 8, 3, 4, 2, 1, 2, 5).Map(func(x int) int {
		return x
	}).SkipLast(3)
	ob.Subscribe(func(x int) {
		res = append(res, x)
	})
	fmt.Print("调用SkipLast(3): ")
	for _, val := range res {
		fmt.Print(val, "  ")
	}
	fmt.Print("\n")

	res = []int{}
	ob = rxgo.Just(1, 8, 3, 4, 2, 1, 2, 5).Map(func(x int) int {
		return x
	}).Take(3)
	ob.Subscribe(func(x int) {
		res = append(res, x)
	})
	fmt.Print("调用Take(3): ")
	for _, val := range res {
		fmt.Print(val, "  ")
	}
	fmt.Print("\n")

	res = []int{}
	ob = rxgo.Just(1, 8, 3, 4, 2, 1, 2, 5).Map(func(x int) int {
		return x
	}).TakeLast(3)
	ob.Subscribe(func(x int) {
		res = append(res, x)
	})
	fmt.Print("调用TakeLast(3): ")
	for _, val := range res {
		fmt.Print(val, "  ")
	}
	fmt.Print("\n")
}
